#!/bin/bash
function check_and_clone(){
	url=$1
	repo_name=`basename $url`
	git_str=`egrep  "\.git"`
	if [ -z ${git_str} ];then
		echo ${git_str}
	fi
	# git clone ${url} /tmp
}
function compile_install(){
    repo=${1}
	cd ${repo}
	compile_file=`find . -maxdepth 1 -type f -name CMakeLists.txt`
	echo "CMake File: ${compile_file}"
	if [ -z "${compile_file}" ];then
		printf "\033[31m不存在CMkeList.txt文件，无法使用CMake编译！\n\033[0m"
	else
		mkdir build
		cd build
		cmake ..
		make -j8
		sudo make install
	fi
}
function install_opencv(){
	opencv_source=$1
	opencv_contrib=$2
	if [ -z ${opencv_source} ];then
		opencv_source=${HOME}/opencv
	fi
	if [ -z ${opencv_contrib} ];then
		opencv_contrib=${HOME}/opencv_contrib
	fi
	printf "\033[31mOpenCV Source: %s OpenCV contrib %s\033[0m\n" ${opencv_source} ${opencv_contrib}
	printf "\033[31mInstall dependency files\033[0m\n"
	sudo apt-get install libgtk-3-dev libgtk2.0-dev libwebp-dev -y
	bash setup_opencv.sh
}
function download_package(){
	url=$1
	save_path=$2
	if [ -z ${save_path} ];then
		save_path=/tmp
	fi
	if [ ! -d ${save_path} ];then
		mkdir -p ${save_path}
	fi
	filename=`basename ${url}`
	temp_savepath=${save_path}/${filename}
	echo "### ${filesname} ${temp_savepath}"
	printf "\033[31m Download file %s and save it to %s\033[0m\n" "${filename}" "${temp_savepath}"
	if [ ! -f ${temp_savepath} ];then
		wget -c $url -O ${temp_savepath}
	fi
}
# 安装基础软件包
# sudo apt install zsh git nmap plank vim deepin-terminal pinta -y
temp_path=/tmp
# 安装GTest
# git clone git@github.com:google/googletest.git /tmp
#compile_install ${HOME}/googletest
# compile_install /home/liushuai/glog
# check_and_clone git@github.com:google/googletest.git

# 安装gflags
# gflags_url=https://codeload.github.com/gflags/gflags/zip/master
# download_package ${gflags_url}
# package_path=`basename ${gflags_url}`
# unzip ${temp_path}/package_path -d ${package_path}
# cd ${temp_path}/gflags-master
# compile_install ${temp_path}/gflags-master
# 安装OpenCV
install_opencv
# download_package http://downloads.webmproject.org/releases/webp/libwebp-1.1.0.tar.gz
# 安装eigen
# unzip ~/下载/eigen-3.3.9.zip -d ${temp_path}
# compile_install ${temp_path}/eigen-3.3.9
# 安装nextcloud
# sudo apt-get install apache2 -y
# sudo apt-get install mariadb-server mariadb-client
# sudo systemctl start mysql
# service mysql restart
# sudo apt-get install php7.0
# 
# sudo apt-get install apache2 mariadb-server libapache2-mod-php7.0
# sudo apt-get install php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring
# sudo apt-get install php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip
